home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_all.zip / TI114.ASC < prev    next >
Text File  |  1992-09-02  |  11KB  |  397 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  10.   VERSION : ALL
  11.        OS : MS-DOS
  12.      DATE : December 4, 1986                             PAGE : 1/6
  13.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  14.  
  15.  
  16.  
  17.  
  18.   The following example routines are public domain programs that
  19.   have been uploaded to our Forum on CompuServe. As a courtesy to
  20.   our users that do not have immediate access to CompuServe,
  21.   Technical Support distributes these routines free of charge.
  22.  
  23.   However, because these routines are public domain programs, not
  24.   developed by Borland International, we are unable to provide any
  25.   technical support or assistance using these routines. If you need
  26.   assistance using these routines, or are experiencing difficu
  27.  
  28.   Thanks to Marshall Brain for the original code for this routine.
  29.  
  30.   These routines provide a method for Turbo Pascal programs to trap
  31.   MS-DOS interrupt 24. INT 24 is called by DOS when a "critical
  32.   error" occurs, and it normally prints the familiar "Abort, Retry,
  33.   Ignore?" message.
  34.  
  35.   With the INT 24 handler installed, errors of this type will be
  36.   passed on to Turbo Pascal as an error. If I/O checking is on,
  37.   this will cause a program crash. If I/O checking is off, IOResult
  38.   will return an error code. The global variable INT24Err will b
  39.  
  40.   In most cases, INT24Result should be used, because INT24Err must
  41.   be set back to false, and DOS sometimes restores its normal INT
  42.   24 handler after an error.
  43.   -------------------------------------------------------------------
  44.   **Note: Turbo's normal IOResult codes (and Turbo Access error
  45.   codes) for MS-DOS DO NOT correspond to I/O error numbers given in
  46.   Appendix I of the Turbo Pascal manual, or error codes given in
  47.   the I/O error nn, PC=aaaa/Program aborted message. Here is
  48.  
  49.     IOResult     Turbo error
  50.    ----------    -----------------------------------------------
  51.      00 (0)      00 (0)     none
  52.      01 (1)      90 (144)   record length mismatch
  53.      02 (2)      01 (1)     file does not exist
  54.      03 (3)      F1 (241)   directory is full
  55.      04 (4)      FF (255)   file disappeared
  56.      05 (5)      02 (2)     file not open for input
  57.      06 (6)      03 (3)     file not open for output
  58.      07 (7)      99 (153)   unexpected end of file
  59.      08 (8)      F0 (240)   disk write error
  60.      09 (9)      10 (16)    error in numeric format
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  76.   VERSION : ALL
  77.        OS : MS-DOS
  78.      DATE : December 4, 1986                             PAGE : 2/6
  79.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  80.  
  81.  
  82.  
  83.  
  84.      0A (10)     99 (153)   unexpected end of file
  85.      0B (11)     F2 (242)   file size overflow
  86.      0C (12)     99 (153)   unexpected end of file
  87.      0D (13)     F0 (240)   disk write error
  88.      0E (14)     91 (145)   seek beyond end of file
  89.      0F (15)     04 (4)     file not open
  90.      10 (16)     20 (32)    operation not allowed on a logical device
  91.      11 (17)     21 (33)    not allowed in direct mode
  92.      12 (18)     22 (34)    assign to standard files is not allowed
  93.      90 (144)    90 (144)   record length mismatch
  94.  
  95.  
  96.   program CriticalError;
  97.  
  98.   Const INT24Err     : Boolean=False;
  99.         INT24ErrCode : Byte=0;
  100.         OldINT24     : Array [1..2] Of Integer=(0,0);
  101.  
  102.   Var RegisterSet    : Record Case Integer Of
  103.                          1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer);
  104.                          2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  105.                        End;
  106.  
  107.   Procedure INT24;
  108.     Const FCBFuncs: Array [1..6] Of Byte=(14,15,21,22,27,28);
  109.     Begin
  110.       { To understand this routine, you will need to read the description of
  111.         Interrupt 24h in the DOS manual.  It also helps to examine and trace the
  112.         generated code under DEBUG. }
  113.       Inline($0E/$0E/$1F/$07/$C6/$06/ INT24Err /$01/$89/$EC/$83/$C4/$08/
  114.              $89/$F8/$A2/ INT24ErrCode /$58/$B9/$06/$00/$BF/ FCBFuncs /$F2/
  115.              $AE/$75/$04/$B0/$01/$EB/$08/$3C/$39/$B0/$FF/$72/$02/$B0/$83/
  116.              $5B/$59/$5A/$5E/$5F/$89/$E5/$80/$4E/$0A/$01/$5D/$1F/$07/$CF);
  117.   {   Turbo:  PUSH BP                    (Save caller's stack frame
  118.               MOV  BP,SP                   Set up this procedure's stack frame
  119.               PUSH BP                     ?)
  120.       Inline: PUSH CS
  121.               PUSH CS
  122.               POP  DS                    Set DS and ES temporarily to CS
  123.               POP  ES
  124.               MOV  BYTE [INT24Err],1     Set INT24Err to True  (CS:)
  125.               MOV  SP,BP                 Get correct SP;  ADD: Discard saved
  126.               ADD  SP,8                    BP, INT 24h return address & flags
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  142.   VERSION : ALL
  143.        OS : MS-DOS
  144.      DATE : December 4, 1986                             PAGE : 3/6
  145.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  146.  
  147.  
  148.  
  149.  
  150.               MOV  AX,DI                 Get INT 24h error code
  151.               MOV  [INT24ErrCode],AL     Save it in INT24ErrCode
  152.               POP  AX                    Get initial DOS call number
  153.               MOV  CX,6                  Search for it in FCBFuncs: is this one
  154.               MOV  DI,Offset FCBFuncs      of the FCB functions that requires an
  155.               REPNZ SCASB                  error code of 01 in AL?
  156.               JNZ  .1
  157.               MOV  AL,1                  Yes: set it
  158.               JMP  .2
  159.  
  160.    .1      CMP  AL,39h                No: is it an FCB function that requires
  161.            MOV  AL,0FFh                 AL=FFh (function <39h)?  Yes: set it.
  162.            JB   .2
  163.            MOV  AL,83h                No: handle call, return error 83h, call
  164.                                         failed via INT 24h.
  165.                                       The error code (1, FFh or 83h) is
  166.                                         returned to the Turbo runtime routine
  167.                                         that called DOS, making it look like
  168.                                         a simple DOS error.  Turbo handles
  169.                                         the I/O error.
  170.    .2      POP  BX                    Pop the rest of the registers saved by
  171.            POP  CX                      the initial INT 21h.
  172.            POP  DX
  173.            POP  SI
  174.            POP  DI
  175.            MOV  BP,SP
  176.            OR   Byte Ptr [BP+0Ah],1   Set the carry flag in the saved Flags reg.
  177.            POP  BP
  178.            POP  DS
  179.            POP  ES
  180.            IRET                       Return to next instruction: all regs.
  181.                                         restored, AL=error code, carry set. }
  182.   End;
  183.  
  184.  
  185.  
  186.  
  187.   Procedure INT24On;  {Enable INT 24 trapping}
  188.   Begin
  189.     INT24Err:=False;
  190.     With RegisterSet Do
  191.     Begin
  192.       AX:=$3524;
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  208.   VERSION : ALL
  209.        OS : MS-DOS
  210.      DATE : December 4, 1986                             PAGE : 4/6
  211.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  212.  
  213.  
  214.  
  215.  
  216.       MsDos(RegisterSet);
  217.       If (OldINT24[1] Or OldINT24[2]) = 0 Then
  218.       Begin
  219.         OldINT24[1]:=ES;
  220.         OldINT24[2]:=BX;
  221.       End;
  222.       DS:=CSeg;
  223.       DX:=Ofs(INT24);
  224.       AX:=$2524;
  225.       MsDos(RegisterSet);
  226.     End;
  227.   End;
  228.  
  229.   Procedure INT24Off;  {Disable INT 24 trapping.  Should be done at the
  230.                         end of the program, if you plan to be running
  231.                         the program from within the Turbo compiler.}
  232.   Begin
  233.     INT24Err:=False;
  234.     If OldINT24[1]<>0 Then
  235.       With RegisterSet Do
  236.       Begin
  237.         DS:=OldINT24[1];
  238.         DX:=OldINT24[2];
  239.         AX:=$2524;
  240.         MsDos(RegisterSet);
  241.       End;
  242.     OldINT24[1]:=0;
  243.     OldINT24[2]:=0;
  244.   End;
  245.  
  246.   Function INT24Result: Integer;
  247.   Var I : Integer;
  248.  
  249.   Begin
  250.     I:=IOResult;
  251.     If INT24Err Then
  252.  
  253.     Begin
  254.       I:=I+256*(INT24ErrCode+1);
  255.       INT24On;
  256.     End;
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  274.   VERSION : ALL
  275.        OS : MS-DOS
  276.      DATE : December 4, 1986                             PAGE : 5/6
  277.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  278.  
  279.  
  280.  
  281.  
  282.     INT24Result:=I;
  283.   End;
  284.  
  285.  
  286.   {  INT24Result returns all the regular Turbo IOResult codes if no
  287.      critical  error has occurred.   If a critical error,  then the
  288.      following  values are added to the error code from Turbo (each
  289.      is 256 times the INT24ErrorCode value returned by DOS):
  290.  
  291.       256:  Attempt to write on write protected disk
  292.       512:  Unknown unit                  [internal dos error]
  293.       768:  Drive not ready               [drive door open or bad drive]
  294.      1024:  Unknown command               [internal dos error]
  295.      1280:  Data error (CRC)              [bad sector or drive]
  296.      1536:  Bad request structure length  [internal dos error]
  297.      1792:  Seek error                    [bad disk or drive]
  298.      2048:  Unknown media type            [bad disk or drive]
  299.      2304:  Sector not found              [bad disk or drive]
  300.      2560:  Printer out of paper          [anything that the printer
  301.                                            might signal]
  302.      2816:  Write fault                   [character device not ready]
  303.      3072   Read fault                    [character device not ready]
  304.      3328:  General failure               [several meanings]
  305.     If you need the IOResult part, use
  306.       I:=INT24Result and 255; [masks out the INT 24 code]
  307.     For the INT 24 code, use
  308.       I:=INT24Result Shr8;    [same as Div 256, except faster]
  309.     INT24Result clears both error codes, so you must assign it  to
  310.     a variable if you want to extract both codes:
  311.       J:=INT24Result;
  312.       Writeln('Turbo IOResult  = ',J And 255);
  313.       Writeln('DOS INT 24 code = ',J Shr 8); }
  314.  
  315.  
  316.   { Main program }
  317.   { Run this with printer off (or no printer), and nothing in drive A }
  318.  
  319.   Var F : File;
  320.       I : Integer;
  321.  
  322.   Procedure PrinterTest;
  323.   Begin
  324.     WriteLn(LST,'test');
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  340.   VERSION : ALL
  341.        OS : MS-DOS
  342.      DATE : December 4, 1986                             PAGE : 6/6
  343.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  344.  
  345.  
  346.  
  347.  
  348.     I:=INT24Result;
  349.     If I<>0 Then
  350.       WriteLn('Printer error: ',I)
  351.     Else
  352.       WriteLn('Printer OK');
  353.   End;
  354.  
  355.   Procedure FileTest;
  356.   Begin
  357.     Assign(F,'A:FILE');
  358.     {$I-}
  359.     Reset(F);
  360.     {$I+}
  361.     I:=INT24Result;
  362.     If I<>0 Then
  363.       WriteLn('Open failure on A:FILE :  INT24Result=',I)
  364.     Else
  365.     begin
  366.       WriteLn('A:FILE exists');
  367.       Close(F);
  368.     end;
  369.   End;
  370.  
  371.   Begin
  372.     INT24On;
  373.     PrinterTest;
  374.     FileTest;
  375.     PrinterTest;
  376.     INT24Off;
  377.     FileTest;
  378.     PrinterTest;
  379.   End.
  380.  
  381.  
  382.   DISCLAIMER: You have the right to use this technical information subject to the
  383.   terms of the No-Nonsense License Statement that you received with the Borland
  384.   product to which this information pertains.
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.